<template>
	<el-dialog :visible.sync="visible" :modal-append-to-body="false" :title="keyLan['name']" class="demo-ruleForm">
		<exAddEdit ref="exAddEdit" v-model="model"></exAddEdit>

		<div slot="footer" class="dialog-footer">
			<el-button v-if="isAdd" @click="resetThisVal('model')">{{comLan["btnReset"]}}</el-button>
			<el-button @click="close">{{comLan["btnCancel"]}}</el-button>
			<el-button type="primary" @click="save" :loading="loading">{{comLan["btnSave"]}}</el-button>
		</div>
	</el-dialog>
</template>

<script>
	import common from "@/common/common.js";
	import js from "./js.js";
	import exAddEdit from "@/Auto/SysCustomerIntention/SysCustomerIntentionAddEdit.vue";

	export default {
		name: "SysCustomerIntentionAdd",
		components: {
			exAddEdit
		},
		props: {
			value: {
				type: Object,
				default: function() {
					return {};
				}
			}
		},
		mixins: [common.baseVM, js],
		data() {
			return {
				model: {
					ID: 0,
					SysCustomerID: null,
					EnumSysCustomerIntention: null,
					CommunicationDate: new Date(),
					TrainContent: null,
					CommunicationContent: null,
					Remark: null,
				}
			}
		},
		methods: {
			init() {},

			show(scope) {
				this.loadBeforeValSuccess = false;
				this.resetVal("model");
				this.isAdd = scope == null || scope.row == null;
				if (this.isAdd) { //新建
					this.loadBeforeVal();
					this.visible = true;
					return;
				}
				var id = scope.row.ID;
				this.get("api/SysCustomerIntention/Get?id=" + id).then(data => {
					this.model = data.Result;
					this.visible = true;
				});
			},
			close() {
				this.visible = false;
			},
			save() {
				this.$refs.exAddEdit.formValidate('formModel', () => {
					var post = JSON.parse(JSON.stringify(this.model));
					this.loading = true;
					this.post('api/SysCustomerIntention/Save', post).then(data => {
						this.showToast(data.Message, "success");
						this.loading = false;
						
						this.clearBeforeVal();
						this.close();
						
						this.$emit("success");
						
						if (this.isAdd && !!this.$listeners["input"]) {
							this.$emit("input", data.Result);
						}
					}).catch((error) => {
						this.loading = false;
					});
				});
			}
		}
	}
</script>
